<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/8/5
  Time: 15:00
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <script type="text/javascript">
      function registerPost(){
          var mobile = document.getElementById("mobile").value;
          //通过ajax异步方式请求服务端
          xmlHttpRequest = new XMLHttpRequest();
          //设置回调函数
          xmlHttpRequest.onreadystatechange = callBack;
          xmlHttpRequest.open("post","MobileServlet",true);
          //设置post方式的头信息
          xmlHttpRequest.setRequestHeader("Content-type","application/x-www-form-urlencoded");
          xmlHttpRequest.send("mobile=" + mobile);
      }

      function registerGet(){
          var mobile = document.getElementById("mobile").value;
          //通过ajax异步方式请求服务端
          xmlHttpRequest = new XMLHttpRequest();
          //设置回调函数
          xmlHttpRequest.onreadystatechange = callBack;
          xmlHttpRequest.open("get","MobileServlet?mobile="  + mobile,true);
          xmlHttpRequest.send(null);
      }

      function callBack(){
          if(xmlHttpRequest.readyState==4 && xmlHttpRequest.status==200){
              //接收服务端返回的数据
              var data = xmlHttpRequest.responseText;
              if(data=="true"){
                  alert("此号码已存在！");
              }else{
                  alert("此号码不存在！");
              }
          }

      }

    </script>

    <title>index</title>
  </head>
  <body>
        手机：<input id="mobile">
        <br/>
        <input type="button" value="检测Post" onclick="registerPost()"/>
        <input type="button" value="检测Get" onclick="registerGet()"/>
  </body>
</html>
